using System;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Text;
public class HttpService
{
	public CookieContainer cookieContainer = new CookieContainer();
	public string post(string url, string data)
	{
		HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
		httpWebRequest.Method = "POST";
		httpWebRequest.ContentType = "application/octet-stream";
		httpWebRequest.CookieContainer = this.cookieContainer;
		Stream requestStream = httpWebRequest.GetRequestStream();
		new StreamWriter(requestStream, Encoding.GetEncoding("utf-8"));
		byte[] array = CryptUtil.smethod_0(data);
		requestStream.Write(array, 0, array.Length);
		requestStream.Close();
		HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
		httpWebResponse.Cookies = this.cookieContainer.GetCookies(httpWebResponse.ResponseUri);
		Stream responseStream = httpWebResponse.GetResponseStream();
		ArrayList arrayList = new ArrayList();
		int num;
		while ((num = responseStream.ReadByte()) != -1)
		{
			arrayList.Add((byte)num);
		}
		int num2 = 0;
		byte[] array2 = new byte[arrayList.Count];
		foreach (byte b in arrayList)
		{
			array2[num2] = b;
			num2++;
		}
		responseStream.Close();
		return CryptUtil.smethod_1(array2, num2);
	}
	public string method_1(string url, string string_1)
	{
		HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
		httpWebRequest.Method = "POST";
		httpWebRequest.ContentType = "application/octet-stream";
		httpWebRequest.CookieContainer = this.cookieContainer;
		Stream requestStream = httpWebRequest.GetRequestStream();
		new StreamWriter(requestStream, Encoding.GetEncoding("utf-8"));
		byte[] array = CryptUtil.smethod_0(string_1);
		requestStream.Write(array, 0, array.Length);
		requestStream.Close();
		HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
		httpWebResponse.Cookies = this.cookieContainer.GetCookies(httpWebResponse.ResponseUri);
		Stream responseStream = httpWebResponse.GetResponseStream();
		ArrayList arrayList = new ArrayList();
		int num;
		while ((num = responseStream.ReadByte()) != -1)
		{
			arrayList.Add((byte)num);
		}
		int num2 = 0;
		byte[] array2 = new byte[arrayList.Count];
		foreach (byte b in arrayList)
		{
			array2[num2] = b;
			num2++;
		}
		responseStream.Close();
		return Encoding.UTF8.GetString(array2, 0, num2);
	}
	public string get(string url, string data)
	{
		HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url + ((data == "") ? "" : "?") + data);
		httpWebRequest.Method = "GET";
		httpWebRequest.ContentType = "text/html;charset=UTF-8";
		Stream responseStream = ((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream();
		StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
		string result = streamReader.ReadToEnd();
		streamReader.Close();
		responseStream.Close();
		return result;
	}
	public string method_3(string url, string string_1, string string_2)
	{
		HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
		httpWebRequest.Method = "POST";
		httpWebRequest.ContentType = "application/octet-stream";
		httpWebRequest.CookieContainer = this.cookieContainer;
		Stream requestStream = httpWebRequest.GetRequestStream();
		new StreamWriter(requestStream, Encoding.GetEncoding("utf-8"));
		byte[] bytes = Encoding.UTF8.GetBytes(string_2);
		requestStream.Write(bytes, 0, bytes.Length);
		requestStream.Close();
		HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
		httpWebResponse.Cookies = this.cookieContainer.GetCookies(httpWebResponse.ResponseUri);
		Stream responseStream = httpWebResponse.GetResponseStream();
		ArrayList arrayList = new ArrayList();
		int num;
		while ((num = responseStream.ReadByte()) != -1)
		{
			arrayList.Add((byte)num);
		}
		int num2 = 0;
		byte[] array = new byte[arrayList.Count];
		foreach (byte b in arrayList)
		{
			array[num2] = b;
			num2++;
		}
		responseStream.Close();
		return Encoding.UTF8.GetString(array, 0, num2);
	}
	public string post_http(string Url, string postDataStr, string cookie)
	{
		WebClient webClient = new WebClient();
		webClient.Headers.Add("X-Requested-With", "XMLHttpRequest");
		webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36");
		webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		webClient.Headers.Add("Referer", Url);
		webClient.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
		webClient.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
		webClient.Headers.Add("Cookie", cookie);
		byte[] array = webClient.UploadData(Url, "POST", Encoding.UTF8.GetBytes(postDataStr));
		string value = webClient.ResponseHeaders["Content-Encoding"];
		string result;
		if ("gzip".Equals(value))
		{
			result = HttpService.zip_to_string(array, Encoding.UTF8);
		}
		else
		{
			result = Encoding.UTF8.GetString(array);
		}
		return result;
	}
	public static string zip_to_string(byte[] byte_0, Encoding encoding)
	{
		MemoryStream stream = new MemoryStream(byte_0);
		MemoryStream memoryStream = new MemoryStream();
		GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress);
		byte[] array = new byte[1000];
		int count;
		while ((count = gZipStream.Read(array, 0, array.Length)) > 0)
		{
			memoryStream.Write(array, 0, count);
		}
		byte_0 = memoryStream.ToArray();
		return encoding.GetString(byte_0);
	}
}
